<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!doctype html>
<html lang="en">

<head>
<title>编辑</title>
	<!-- bootstrap -->
<link type="text/css" rel="stylesheet" href="${ctx}/static/bootstrap/bootstrap.min.css">

<link href="${ctx}/static/xform/styles/layout3.css" rel="stylesheet">
<link href="${ctx}/static/xform/styles/xform.css" rel="stylesheet">
<script type="text/javascript" src="${ctx}/static/xform/designer-xform-all.js"></script>
<script type="text/javascript" src="${ctx}/static/xform/container-layout.js"></script>
<script type="text/javascript" src="${ctx}/static/xform/adaptor.js"></script>
<script src="${ctx}/static/selectWin/userSelector.js" type="text/javascript"></script>
<script type="text/javascript">
document.onmousedown = function(e) {};
document.onmousemove = function(e) {};
document.onmouseup = function(e) {};
document.ondblclick = function(e) {};

var buttons = [];
<c:forEach items="${formInfo.buttons}" var="item">
buttons.push('${item}');
</c:forEach>

if (buttons.length == 0) {
	buttons = ['完成任务'];
}

$(function() {
    /* $("#demoForm").validate({
        submitHandler: function(form) {
			bootbox.animate(false);
			var box = bootbox.dialog('<div class="progress progress-striped active" style="margin:0px;"><div class="bar" style="width: 100%;"></div></div>');
            form.submit();
        },
        errorClass: 'validate-error'
    }); */

	$(document).delegate('#xf-form-table-foot button', 'click', function(e) {
		switch($(this).html()) {
			case '保存草稿':
				$('#xf-form').attr('action', '${ctx}/bpm/confForm/form-saveDraft');
				$('#xf-form').submit();
				break;
			case '完成任务':
				$('#xf-form').attr('action', '${ctx}/bpm/confForm/form-completeTask');
				$('#xf-form').submit();
				break;
			case '发起流程':
				$('#xf-form').attr('action', '${ctx}/bpm/confForm/form-startProcessInstance');
				$('#xf-form').submit();
				break;
			case '驳回':
				$('#xf-form').attr('action', '${ctx}/bpm/confForm/task-rollback');
				$('#xf-form').submit();
				break;
			case '转办':
				$(this).attr('title','转办是把任务转给其他人操作，被转办人会在待办任务列表里看到这条任务，正常处理任务后，流程会继续向下运行。');
				$('#modal form').attr('action', '${ctx}/bpm/confForm/task-doDelegate');
				$('#modal').dialog({
		            title: "设置转办人员"
		        }).dialog("open");
				break;
			case '协办':
				$(this).attr('title','协办是把任务转给其他人操作，被转办人会在待办任务列表里看到这条任务，正常处理任务后，任务会返回给原执行人，流程不会发生变化。');
				$('#modal form').attr('action', '${ctx}/bpm/confForm/task-doDelegateHelp');
				$('#modal').dialog({
		            title: "设置协办人员"
		        }).dialog("open");
				break;
		}
	});
    
    $(".userSelector").click(function() {
		var $this = $(this);
		$.easyui.showGridSelector($.extend(window.userSelectOpts, {
			onEnter : function(val) {
				$this.prev().val("人员:" + val[0].trueName);
				$this.prev().prev().val( val[0].id);
			}
		}));
	});

	setTimeout(function() {
		if (!!xform.model.template) {
			xform.setValue(${json});
			xform.model.template.buttons = buttons;
			xform.model.template.initFoot();
			var id = '#xf-form-table-body-row' + (xform.model.template.positions.length - 1);
			var el = $(id)[0];
			el.parentNode.removeChild(el);
		} else {
			$('#__gef_container__').hide();
			$('#m-main').append('<form action="${ctx}/form/form-completeTask.do"><button name="taskId" value="${formInfo.taskId}">完成</button></form>');
		}
	}, 500);
})
    </script>
</head>

<body>
    <div class="row-fluid">
	<!-- start of main -->
    <section id="m-main" class="span10" style="float:left;width:100%">
	  <div id="__gef_container__" style="padding-left:5px;">
		<div id="__gef_canvas__" style="float:left;clear:right;overflow:auto;">
		  <div id="xf-center" class="xf-center" unselectable="on">
			<div id="xf-layer-form" class="xf-layer-form">
			  <form id="xf-form" method="post" action="${ctx}/form/form-completeTask.do" class="xf-form">
				<input id="taskId" type="hidden" name="taskId" value="${formInfo.taskId}">
				<input id="businessKey" type="hidden" name="businessKey" value="${dynamicModel.id}">
				<!--
				<input id="processDefinitionId" type="hidden" name="processDefinitionId" value="${processDefinitionId}">
				-->
				<table id="xf-form-table" class="xf-form-table">
				  <thead id="xf-form-table-head"><tr><th>Title</th></tr></thead>
				  <tbody id="xf-form-table-body"><tr><td>Body</td></tr></tbody>
				  <tfoot id="xf-form-table-foot"><tr><td>Footer</td></tr></tfoot>
				</table>
			  </form>
			</div>
		  </div>
		</div>
	  </div>

    </section>
	<!-- end of main -->

		<form id="f" action="form-template-save.do" method="post" style="display: none;">
			<textarea id="__gef_content__" name="content">${formTemplate.content}</textarea>
		</form>
		<div id="modal" class="easyui-dialog" data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true,width: 320, height:200,
		            maximizable: true,
		            autoRestore: true,
		            autoVCenter: true,
		            autoHCenter: true">
			<form>
				<input type="hidden" name="taskId" value="${formInfo.taskId}" />
				<div style="margin:20px">
					<input type="hidden" name="attorney" class="input-medium" value="">
					<input type="text" style="width: 175px;" value="">
					<a class="userSelector easyui-linkbutton easyui-tooltip" data-options="plain: true, iconCls: 'icon-metro-search',content:'选取人员'"></a>
					<br>
					<button class="btn">提交</button>
				</div>
			</form>
		</div>
	</div>
  </body>
</html>
